package com.jacky.iot;

import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * 通过http客户端上传设备的遥测数据
 */
public class HttpTelemetry {

    private static final String BASE_URL = "http://127.0.0.1:8080/api/v1/";

    public static void main(String[] args) {

        String URL_SUFFIX = "sgj4mhjtgr6svu55m79x/telemetry";

        RestTemplate rest = new RestTemplate();
        Map<String, Object> telemetry = Map.of("temperature", 31,"humidity", 68);

        ResponseEntity<String> response = rest.postForEntity(BASE_URL + URL_SUFFIX, telemetry, String.class);
        System.out.println("resp:" + response.getBody());
    }
}